<?php
namespace app\admin\controller;
use think\Controller;
class Login extends Controller
{
    public function login()
    {
    	if(request()->isPost()){
    		$post = input('post.');
    		$name = $post['name'];
    		$password = $post['password'];
    		$userData = db('admin') -> where(['name' => $name]) -> find();
    		if($userData){
    			if($userData['password'] === $password ){
    				session('name',$userData['name']);
    				session('id',$userData['id']);
    				return 1;
    			}
    		}
    		return 0;
    	}
        return $this -> fetch();
    }
    public function logout(){
    	session(null);
    	$this->redirect('login');
    }
}
